package calbuilder;

import java.time.DayOfWeek;
import java.time.Instant;

import java.time.LocalDate;
import java.time.LocalDateTime;

import java.time.LocalTime;

import java.time.Month;

import java.time.MonthDay;

import java.time.Year;

import java.time.YearMonth;

import java.time.format.DateTimeFormatter;

import java.util.Date;

public class DatesFunctions {
    public static void main(String[] args) {
        DemoInstant(new Date(System.currentTimeMillis()));
    }
    
    public static void DemoInstant(Date oldDate){
        Instant foo = Instant.now();
        Date Dinstant = Date.from(foo);
        
        LocalDateTime ldt = LocalDateTime.now();
        LocalDate ld = LocalDate.now();
        LocalTime lt = LocalTime.now();
        Year yr = Year.now();
        Month mo = ld.getMonth();
        YearMonth ym = YearMonth.now();
        MonthDay md = MonthDay.now();
        DayOfWeek dw = ld.getDayOfWeek();
        
        System.out.println("Old Style Date: " + oldDate);
        System.out.println("New Style Instant: " + foo);
        System.out.println("New from old: " + Dinstant);
        System.out.println();
        System.out.println("LocalDateTime = " + ldt);
        System.out.println("LocalDate = " + ld);
        System.out.println("LocalTime = " + lt);
        System.out.println("Year = " + yr);
        System.out.println("Month = " + mo);
        System.out.println("YearMonth = " + ym);
        System.out.println("MonthDay = " + md);
        System.out.println("DayOfWeek = " + dw);
        System.out.println();
        System.out.println("Formatted LocalDateTime as dd/MM/yyyy");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        String text = ldt.format(formatter);
        System.out.println(text);
    }
    
}
